From 0cb97f4d8bff4b430318d74d7235ec3568ec5771 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Wed, 7 Mar 2007 10:53:34 +0000 Subject: [PATCH] dump-core: always use elfclass64 format to support x86_32pae. Without this patch xen dump-core format can't handle over 4GB case. Signed-off-by: Isaku Yamahata --- docs/misc/dump-core-format.txt | 14 ++++++++++---- tools/libxc/xc_core.c | 26 +++++++++++++------------- tools/libxc/xc_core.h | 4 ++-- tools/libxc/xc_core_ia64.c | 4 ++-- tools/libxc/xc_core_ia64.h | 2 +- tools/libxc/xc_core_x86.h | 2 +- tools/libxc/xc_ptrace_core.c | 24 +++++++++++++----------- 7 files changed, 42 insertions(+), 34 deletions(-) diff --git a/docs/misc/dump-core-format.txt b/docs/misc/dump-core-format.txt index ce759f39a0..99384ca94a 100644 --- a/docs/misc/dump-core-format.txt +++ b/docs/misc/dump-core-format.txt @@ -26,11 +26,12 @@ For xen related structure, please see the xen header files. Elf header ---------- The elf header members are set as follows + e_ident[EI_CLASS] = ELFCLASS64 = 2 e_ident[EI_OSABI] = ELFOSABI_SYSV = 0 e_type = ET_CORE = 4 -e_ident[EI_CLASS], e_ident[EI_DATA] and e_flags are set according -to an architecture which a file is created. Other members are set as usual. - +ELFCLASS64 is always used independent of architecture. +e_ident[EI_DATA] and e_flags are set according to the dumping system's +architecture. Other members are set as usual. Sections -------- @@ -221,5 +222,10 @@ format_version descriptor Format version history ---------------------- -The currently only (major, minor) = (0, 1) is used. +Currently only (major, minor) = (0, 1) is used. [When the format is changed, it would be described here.] + +(0, 1) update +- EI_CLASS member of elf header was changed to ELFCLASS64 independent of + architecture. This is mainly for x86_32pae. + The format version isn't bumped because analysis tools can distinguish it. diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c index 7f6f0ee67a..3dcf51e131 100644 --- a/tools/libxc/xc_core.c +++ b/tools/libxc/xc_core.c @@ -153,7 +153,7 @@ struct xc_core_section_headers { uint16_t num; uint16_t num_max; - Elf_Shdr *shdrs; + Elf64_Shdr *shdrs; }; #define SHDR_INIT 16 #define SHDR_INC 4 @@ -184,14 +184,14 @@ xc_core_shdr_free(struct xc_core_section_headers *sheaders) free(sheaders); } -Elf_Shdr* +Elf64_Shdr* xc_core_shdr_get(struct xc_core_section_headers *sheaders) { - Elf_Shdr *shdr; + Elf64_Shdr *shdr; if ( sheaders->num == sheaders->num_max ) { - Elf_Shdr *shdrs; + Elf64_Shdr *shdrs; if ( sheaders->num_max + SHDR_INC < sheaders->num_max ) { errno = E2BIG; @@ -212,7 +212,7 @@ xc_core_shdr_get(struct xc_core_section_headers *sheaders) } int -xc_core_shdr_set(Elf_Shdr *shdr, +xc_core_shdr_set(Elf64_Shdr *shdr, struct xc_core_strtab *strtab, const char *name, uint32_t type, uint64_t offset, uint64_t size, @@ -317,15 +317,15 @@ xc_domain_dumpcore_via_callback(int xc_handle, uint64_t *pfn_array = NULL; - Elf_Ehdr ehdr; - unsigned long filesz; - unsigned long offset; - unsigned long fixup; + Elf64_Ehdr ehdr; + uint64_t filesz; + uint64_t offset; + uint64_t fixup; struct xc_core_strtab *strtab = NULL; uint16_t strtab_idx; struct xc_core_section_headers *sheaders = NULL; - Elf_Shdr *shdr; + Elf64_Shdr *shdr; /* elf notes */ struct elfnote elfnote; @@ -460,7 +460,7 @@ xc_domain_dumpcore_via_callback(int xc_handle, ehdr.e_ident[EI_MAG1] = ELFMAG1; ehdr.e_ident[EI_MAG2] = ELFMAG2; ehdr.e_ident[EI_MAG3] = ELFMAG3; - ehdr.e_ident[EI_CLASS] = ELFCLASS; + ehdr.e_ident[EI_CLASS] = ELFCLASS64; ehdr.e_ident[EI_DATA] = ELF_ARCH_DATA; ehdr.e_ident[EI_VERSION] = EV_CURRENT; ehdr.e_ident[EI_OSABI] = ELFOSABI_SYSV; @@ -474,9 +474,9 @@ xc_domain_dumpcore_via_callback(int xc_handle, ehdr.e_shoff = sizeof(ehdr); ehdr.e_flags = ELF_CORE_EFLAGS; ehdr.e_ehsize = sizeof(ehdr); - ehdr.e_phentsize = sizeof(Elf_Phdr); + ehdr.e_phentsize = sizeof(Elf64_Phdr); ehdr.e_phnum = 0; - ehdr.e_shentsize = sizeof(Elf_Shdr); + ehdr.e_shentsize = sizeof(Elf64_Shdr); /* ehdr.e_shnum and ehdr.e_shstrndx aren't known here yet. fill it later*/ /* create section header */ diff --git a/tools/libxc/xc_core.h b/tools/libxc/xc_core.h index cf5b15d12b..5b1c9b5a33 100644 --- a/tools/libxc/xc_core.h +++ b/tools/libxc/xc_core.h @@ -116,10 +116,10 @@ struct xen_dumpcore_p2m { struct xc_core_strtab; struct xc_core_section_headers; -Elf_Shdr* +Elf64_Shdr* xc_core_shdr_get(struct xc_core_section_headers *sheaders); int -xc_core_shdr_set(Elf_Shdr *shdr, +xc_core_shdr_set(Elf64_Shdr *shdr, struct xc_core_strtab *strtab, const char *name, uint32_t type, uint64_t offset, uint64_t size, diff --git a/tools/libxc/xc_core_ia64.c b/tools/libxc/xc_core_ia64.c index 9ae7dad8c0..455d532ee2 100644 --- a/tools/libxc/xc_core_ia64.c +++ b/tools/libxc/xc_core_ia64.c @@ -266,10 +266,10 @@ int xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, struct xc_core_section_headers *sheaders, struct xc_core_strtab *strtab, - unsigned long *filesz, unsigned long offset) + uint64_t *filesz, uint64_t offset) { int sts = -1; - Elf_Shdr *shdr; + Elf64_Shdr *shdr; /* mmapped priv regs */ shdr = xc_core_shdr_get(sheaders); diff --git a/tools/libxc/xc_core_ia64.h b/tools/libxc/xc_core_ia64.h index 1690e01689..6357dfa20e 100644 --- a/tools/libxc/xc_core_ia64.h +++ b/tools/libxc/xc_core_ia64.h @@ -42,7 +42,7 @@ int xc_core_arch_context_get_shdr(struct xc_core_arch_context* arch_ctxt, struct xc_core_section_headers *sheaders, struct xc_core_strtab *strtab, - unsigned long *filesz, unsigned long offset); + uint64_t *filesz, uint64_t offset); int xc_core_arch_context_dump(struct xc_core_arch_context* arch_ctxt, void* args, dumpcore_rtn_t dump_rtn); diff --git a/tools/libxc/xc_core_x86.h b/tools/libxc/xc_core_x86.h index b3c2d5beec..53ca48493d 100644 --- a/tools/libxc/xc_core_x86.h +++ b/tools/libxc/xc_core_x86.h @@ -45,7 +45,7 @@ static inline int xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, struct xc_core_section_headers *sheaders, struct xc_core_strtab *strtab, - unsigned long *filesz, unsigned long offset) + uint64_t *filesz, uint64_t offset) { *filesz = 0; return 0; diff --git a/tools/libxc/xc_ptrace_core.c b/tools/libxc/xc_ptrace_core.c index 419b3e55af..82d06bb2d8 100644 --- a/tools/libxc/xc_ptrace_core.c +++ b/tools/libxc/xc_ptrace_core.c @@ -192,7 +192,7 @@ pread_exact(int fd, void* buffer, size_t size, off_t offset) struct elf_core { int domfd; - Elf_Ehdr ehdr; + Elf64_Ehdr ehdr; char* shdr; @@ -242,6 +242,8 @@ elf_core_init(struct elf_core* ecore, int domfd) /* check elf header */ if (!IS_ELF(ecore->ehdr) || ecore->ehdr.e_type != ET_CORE) goto out; + if (ecore->ehdr.e_ident[EI_CLASS] != ELFCLASS64) + goto out; /* check elf header more: EI_DATA, EI_VERSION, e_machine... */ /* read section headers */ @@ -294,7 +296,7 @@ elf_core_search_note(struct elf_core* ecore, const char* name, uint32_t type, } static int -elf_core_alloc_read_sec(struct elf_core* ecore, const Elf_Shdr* shdr, +elf_core_alloc_read_sec(struct elf_core* ecore, const Elf64_Shdr* shdr, char** buf) { int ret; @@ -309,19 +311,19 @@ elf_core_alloc_read_sec(struct elf_core* ecore, const Elf_Shdr* shdr, return ret; } -static Elf_Shdr* +static Elf64_Shdr* elf_core_shdr_by_index(struct elf_core* ecore, uint16_t index) { if (index >= ecore->ehdr.e_shnum) return NULL; - return (Elf_Shdr*)(ecore->shdr + ecore->ehdr.e_shentsize * index); + return (Elf64_Shdr*)(ecore->shdr + ecore->ehdr.e_shentsize * index); } static int elf_core_alloc_read_sec_by_index(struct elf_core* ecore, uint16_t index, char** buf, uint64_t* size) { - Elf_Shdr* shdr = elf_core_shdr_by_index(ecore, index); + Elf64_Shdr* shdr = elf_core_shdr_by_index(ecore, index); if (shdr == NULL) return -1; if (size != NULL) @@ -329,14 +331,14 @@ elf_core_alloc_read_sec_by_index(struct elf_core* ecore, uint16_t index, return elf_core_alloc_read_sec(ecore, shdr, buf); } -static Elf_Shdr* +static Elf64_Shdr* elf_core_shdr_by_name(struct elf_core* ecore, const char* name) { const char* s; for (s = ecore->shdr; s < ecore->shdr + ecore->ehdr.e_shentsize * ecore->ehdr.e_shnum; s += ecore->ehdr.e_shentsize) { - Elf_Shdr* shdr = (Elf_Shdr*)s; + Elf64_Shdr* shdr = (Elf64_Shdr*)s; if (strncmp(ecore->shstrtab + shdr->sh_name, name, strlen(name)) == 0) return shdr; @@ -348,7 +350,7 @@ elf_core_shdr_by_name(struct elf_core* ecore, const char* name) static int elf_core_read_sec_by_name(struct elf_core* ecore, const char* name, char* buf) { - Elf_Shdr* shdr = elf_core_shdr_by_name(ecore, name); + Elf64_Shdr* shdr = elf_core_shdr_by_name(ecore, name); return pread_exact(ecore->domfd, buf, shdr->sh_size, shdr->sh_offset); } @@ -357,7 +359,7 @@ static int elf_core_alloc_read_sec_by_name(struct elf_core* ecore, const char* name, char** buf, uint64_t* size) { - Elf_Shdr* shdr = elf_core_shdr_by_name(ecore, name); + Elf64_Shdr* shdr = elf_core_shdr_by_name(ecore, name); if (shdr == NULL) return -1; if (size != NULL) @@ -508,8 +510,8 @@ xc_waitdomain_core_elf( struct xen_dumpcore_elfnote_xen_version *xen_version; struct xen_dumpcore_elfnote_format_version *format_version; - Elf_Shdr* table_shdr; - Elf_Shdr* pages_shdr; + Elf64_Shdr* table_shdr; + Elf64_Shdr* pages_shdr; if (elf_core_init(&ecore, domfd) < 0) goto out; -- 2.30.2